var BackofficePermission = {
	load : function () {
		this.createGrid(); 
		Ext.getDom("welcome").innerHTML =  getUser().Name;		
	},
	
	createGrid : function () {
	 	 BackofficePermission.store = new Ext.data.JsonStore ({
	 	 	url:"/ad/sys/com/control/UserService.php?action=getUserAll",
			root : "row",
			method : "GET",
			remoteSort: false,
			totalProperty: 'count',
			fields : ["Account", "Name", "Status"]
		});
	 
		BackofficePermission.grid =new Ext.grid.GridPanel({
			renderTo : "grid",
			store :  BackofficePermission.store,
			height: 340,
			loadMask : true,
			viewConfig : {
				forceFit : true 
			},
			columns : [ 
				new Ext.grid.RowNumberer(),
				{header : "帳號" ,dataIndex : "Account", width :80,sortable : true , renderer: function (v,p,r) {
					return String.format('<b><a href="/ad/html/backoffice/backofficeMDetail.php?account={0}">{1}</a></b>',r.data.Account,v);	
				}},
				{header : "姓名", dataIndex : "Name",width :40, sortable : true},
				{header : "狀態", dataIndex : "Status",width :30,sortable : true,
					renderer: function (value, p , record) {
						switch (value) {
							case "0": return "停用";
							case "1": return "啟用";
						}
					} 
				},
				{header : " ", width : 40,   renderer: function (v,p,r) {
					return  String.format('<input type="button"  class="gridBtn" onclick=location.href=\'backofficePermissionDetail.php?account={0}\'  value="編輯"/>', r.data.Account );   	
				}} 
			],
			
			bbar : new Ext.PagingToolbar({
				pageSize :10,
				store : BackofficePermission.store,
				displayInfo : true,
				displayMsg : "顯示第 {0} 筆到 {1} 筆紀錄,共 {2} 筆紀錄",
				emptyMsg : "沒有紀錄" 
			})
		});	
		
		BackofficePermission.store.load({
			params:{
				start:0,
				limit:10 
			} 
		});    
	}
	
	
}


Ext.onReady(function (){
	BackofficePermission.load();
});